import Error from 'next/error';
import { IconContext } from 'react-icons';
import { GoFile, GoFileDirectory, GoGitCommit } from 'react-icons/go';
import ReactMarkdown from 'react-markdown';
import gfm from 'remark-gfm';
import hljs from 'highlight.js';
import path from 'path';
const linkClasses = 'text-blue-600 hover:underline';
function getRawURL(pathArray) {
return `/${pathArray[0]}/raw/${pathArray.slice(2).join('/')}`;
}
function getLanguage(filename) {
switch (path.extname(filename)) {
case '.java':
return 'java';
case '.html':
case '.xml':
return 'xml';
case '.md':
return 'md';
case '.c':
case '.h':
return 'c';
case '.tex':
return 'tex';
case '.js':
return 'js';
case '.fs':
return 'fs';
case '.elm':
return 'elm';
case '.json':
return 'json';
case '.py':
return 'py';
case '.css':
return 'css';
default:
return 'plaintext';
}
}
function isImage(filename) {
switch (path.extname(filename)) {
case '.gif':
case '.jpeg':
case '.jpg':
case '.png':
case '.tiff':
case '.tif':
return true;
default:
return false;
}
}
function makeBreadCrumbObj(name, pathArray) {
const breadCrumbObj = {
name: name,
href: `/${pathArray.join('/')}`,
};
return breadCrumbObj;
}
async function getServerSideProps(context) {
const res = await fetch(`http://localhost:3000/api${context.resolvedUrl}`);
const data = await res.json();
if (data.resultType === 'notFound') {
return { notFound: true };
} else {
return { props: { data } };
}
}
function Button({ label, url }) {
return (
{label}
);
}
function ListItemWithIcon({ icon, iconColor, name, url }) {
return (
{icon}
{name}
);
}
function MainContentContainer({ children }) {
return (
{children}
);
}
function LineNos({ textBlob }) {
const count = textBlob.split('\n').length;
const lineNos = [...Array(count).keys()].map((x) => x + 1).join('\n');
return (
{lineNos}
);
}
function CodeBlock({ textBlob, resultPath }) {
const language = getLanguage(resultPath[resultPath.length - 1]);
const highlightedHTML =
hljs.highlight(textBlob, { language: language, ignoreIllegals: true }).value;
return (
);
}
function TextDisplayGrid({ textBlob, resultPath }) {
return (
);
}
function BreadCrumbTrail({ pathArray }) {
const recursion = (acc) => {
if (acc.length === pathArray.length - 4) {
return acc;
} else {
const subArray = pathArray.slice(0, 1).concat('tree', pathArray.slice(2, acc.length + 4));
const breadCrumb = makeBreadCrumbObj(pathArray[acc.length + 3], subArray);
const newAcc = acc.concat([breadCrumb]);
return recursion(newAcc);
}
};
if (pathArray.length < 4) {
return null;
}
let rootArray;
if (pathArray[2] === 'master') {
rootArray = pathArray.slice(0, 1);
} else {
rootArray = pathArray.slice(0, 1).concat('tree', pathArray[2]);
}
const headBreadCrumb = makeBreadCrumbObj(pathArray[0], rootArray);
const tailBreadCrumbs = recursion([]);
const breadCrumbs = [headBreadCrumb].concat(tailBreadCrumbs);
return (
{breadCrumbs.map((breadCrumb, index) => (
{breadCrumb.name} /
))}
{pathArray[pathArray.length - 1]}
);
}
function ReadmeDisplay({ resultContent, resultPath }) {
const imageURITransformer = (uri) => `/${resultPath[0]}/raw/master/${uri}`;
const titleClasses = 'text-2xl text-slate-800 pb-4 border-b border-slate-300';
const articleClasses = 'pt-4 prose md:prose-xl prose-slate max-w-none prose-a:text-blue-600 prose-a:no-underline hover:prose-a:underline';
return (
{resultContent.readmeName}
);
}
function TextBlobArea({ resultContent, resultPath }) {
return (
);
}
function BinaryBlobArea({ resultPath }) {
let binaryDisplay;
if (isImage(resultPath[resultPath.length - 1])) {
binaryDisplay = ;
} else {
binaryDisplay = Binary content cannot be displayed.
;
}
return (
{binaryDisplay}
);
}
function MidSection({ resultPath }) {
return (
);
}
function DirectoryListing({ resultContent, resultPath }) {
const makeURL = (repoRequest, item) => {
const parentTail = resultPath.length > 2 ? resultPath.slice(2) : ['master'];
const parentPath = resultPath.slice(0, 1).concat(repoRequest, parentTail);
const url = `/${parentPath.join('/')}/${item}`;
return url;
}
return (
{resultContent.trees.map((item, index) => (
}
iconColor={'text-blue-400'}
name={item}
url={makeURL('tree', item)}
/>
))}
{resultContent.blobs.map((item, index) => (
}
iconColor={'text-slate-500'}
name={item}
url={makeURL('blob', item)}
/>
))}
);
}
function CommitListing({ resultContent, resultPath }) {
const subArray = resultContent.slice(1);
return (
}
iconColor={'text-slate-500'}
name={resultContent[0].message}
url={`/${resultPath[0]}`}
/>
{subArray.map((item, index) => (
}
iconColor={'text-slate-500'}
name={item.message}
url={`/${resultPath[0]}/tree/${item.id}`}
/>
))}
);
}
function RepositoryListing({ repositories }) {
return (
);
}
function PageSubstance({ data }) {
switch (data.resultType) {
case 'home':
return ;
break;
case 'rootDirectory':
return (
{data.resultContent.readmeExists && (
)}
);
break;
case 'nonRootDirectory':
return (
);
break;
case 'textBlob':
return (
);
break;
case 'binaryBlob':
return (
);
break;
case 'commits':
return (
);
break;
}
}
function Header({ resultPath }) {
return (
);
}
function Main({ data }) {
switch (data.resultType) {
case 'home':
case 'rootDirectory':
case 'nonRootDirectory':
case 'textBlob':
case 'binaryBlob':
case 'commits':
return (
);
break;
default:
return ;
}
}
export { getServerSideProps };
export default Main;